set(PACKAGE_VERSION "@NGSOLVE_VERSION@")
find_package(Netgen CONFIG REQUIRED HINTS
  ${CMAKE_CURRENT_LIST_DIR}
  ${CMAKE_CURRENT_LIST_DIR}/..
  ${CMAKE_CURRENT_LIST_DIR}/../netgen
)

get_filename_component(NGSOLVE_DIR  "${NETGEN_DIR}"  ABSOLUTE)

get_filename_component(NGSOLVE_INSTALL_DIR "${CMAKE_CURRENT_LIST_DIR}/@CMAKE_TO_PREFIX_RELPATH@" ABSOLUTE)
get_filename_component(NGSOLVE_INCLUDE_DIR  "${NETGEN_INCLUDE_DIR}"  ABSOLUTE)
get_filename_component(NGSOLVE_BINARY_DIR   "${NETGEN_BINARY_DIR}"   ABSOLUTE)
get_filename_component(NGSOLVE_LIBRARY_DIR  "${NETGEN_LIBRARY_DIR}"  ABSOLUTE)
get_filename_component(NGSOLVE_PYTHON_DIR   "${NETGEN_PYTHON_DIR}"   ABSOLUTE)
get_filename_component(NGSOLVE_RESOURCE_DIR "${NETGEN_RESOURCE_DIR}" ABSOLUTE)

set(NGSOLVE_INCLUDE_DIRS "@NGSOLVE_INCLUDE_DIRS@;${NETGEN_INCLUDE_DIRS}")

set(NGSOLVE_CXX_COMPILER "@CMAKE_CXX_COMPILER@")
set(NGSOLVE_CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@")

set(NGSOLVE_CMAKE_THREAD_LIBS_INIT "@CMAKE_THREAD_LIBS_INIT@")
set(NGSOLVE_MKL_LIBRARIES "@MKL_LIBRARIES@")
set(NGSOLVE_PYBIND_INCLUDE_DIR "@NETGEN_PYBIND_INCLUDE_DIR@")
set(NGSOLVE_PYTHON_INCLUDE_DIRS "@NETGEN_PYTHON_INCLUDE_DIRS@")
set(NGSOLVE_PYTHON_LIBRARIES "@NETGEN_PYTHON_LIBRARIES@")
set(NGSOLVE_PYTHON_PACKAGES_INSTALL_DIR  "@NETGEN_PYTHON_PACKAGES_INSTALL_DIR@")
set(NGSOLVE_TCL_INCLUDE_PATH "@NETGEN_TCL_INCLUDE_PATH@")
set(NGSOLVE_TCL_LIBRARY "@NETGEN_TCL_LIBRARY@")
set(NGSOLVE_TK_DND_LIBRARY "@NETGEN_TK_DND_LIBRARY@")
set(NGSOLVE_TK_INCLUDE_PATH "@NETGEN_TK_INCLUDE_PATH@")
set(NGSOLVE_TK_LIBRARY "@NETGEN_TK_LIBRARY@")
set(NGSOLVE_X11_X11_LIB "@NETGEN_X11_X11_LIB@")
set(NGSOLVE_X11_Xmu_LIB "@NETGEN_X11_Xmu_LIB@")
set(NGSOLVE_ZLIB_INCLUDE_DIRS "@NETGEN_ZLIB_INCLUDE_DIRS@")
set(NGSOLVE_ZLIB_LIBRARIES "@NETGEN_ZLIB_LIBRARIES@")

set(NGSOLVE_INTEL_MIC       @INTEL_MIC@)
set(NGSOLVE_USE_CCACHE @USE_CCACHE@)
set(NGSOLVE_USE_CUDA        @USE_CUDA@)
set(NGSOLVE_USE_GUI @NETGEN_USE_GUI@)
set(NGSOLVE_USE_LAPACK      @USE_LAPACK@)
set(NGSOLVE_USE_MKL         @USE_MKL@)
set(NGSOLVE_USE_MPI @NETGEN_USE_MPI@)
set(NGSOLVE_USE_MUMPS       @USE_MUMPS@)
set(NGSOLVE_USE_NUMA        @USE_NUMA@)
set(NGSOLVE_USE_PARDISO     @USE_PARDISO@)
set(NGSOLVE_USE_PYTHON @NETGEN_USE_PYTHON@)
set(NGSOLVE_USE_UMFPACK     @USE_UMFPACK@)
set(NGSOLVE_USE_VT          @USE_VT@)
set(NGSOLVE_USE_VTUNE       @USE_VTUNE@)
set(NGSOLVE_MAX_SYS_DIM       @MAX_SYS_DIM@)

set(NGSOLVE_COMPILE_FLAGS "@ngscxx_define_flags@" CACHE STRING "Preprocessor definitions of ngscxx")
set(NGSOLVE_LINK_FLAGS "@ngsld_flags@" CACHE STRING "Link flags set in ngsld")
set(NGSOLVE_INCLUDE_DIRS @ngscxx_include_dirs@ CACHE STRING "Include dirs set in ngscxx")

set(NGSOLVE_INSTALL_DIR_PYTHON  @NGSOLVE_INSTALL_DIR_PYTHON@)
set(NGSOLVE_INSTALL_DIR_BIN     @NGSOLVE_INSTALL_DIR_BIN@)
set(NGSOLVE_INSTALL_DIR_LIB     @NGSOLVE_INSTALL_DIR_LIB@)
set(NGSOLVE_INSTALL_DIR_INCLUDE @NGSOLVE_INSTALL_DIR_INCLUDE@)
set(NGSOLVE_INSTALL_DIR_CMAKE   @NGSOLVE_INSTALL_DIR_CMAKE@)
set(NGSOLVE_INSTALL_DIR_RES     @NGSOLVE_INSTALL_DIR_RES@)

include(${CMAKE_CURRENT_LIST_DIR}/ngsolve-targets.cmake)

if(WIN32)
	# Libraries like ngstd, ngbla etc. are only dummy libs on Windows (there is only one library libngsolve.dll)
	# make sure that all those dummy libs link ngsolve when used with CMake
	target_link_libraries(ngstd INTERFACE ngsolve)
endif(WIN32)

if(NGSOLVE_USE_PYTHON)
  function(add_ngsolve_python_module target)
    if(NOT CMAKE_BUILD_TYPE)
      message(STATUS "Setting build type to NGSolve build type: ${NGSOLVE_CMAKE_BUILD_TYPE}")
      set(CMAKE_BUILD_TYPE ${NGSOLVE_CMAKE_BUILD_TYPE} PARENT_SCOPE)
    endif()
    add_library(${target} SHARED ${ARGN})

    find_package(PythonInterp 3 REQUIRED)
    find_package(PythonLibs 3 REQUIRED)
    target_include_directories(${target} PRIVATE ${PYTHON_INCLUDE_DIR})

    if(NETGEN_BUILD_FOR_CONDA)
        if(APPLE)
            target_link_options(${target} PUBLIC -undefined dynamic_lookup)
        endif(APPLE)
    else(NETGEN_BUILD_FOR_CONDA)
        target_link_libraries(${target} PUBLIC ${PYTHON_LIBRARY})
    endif(NETGEN_BUILD_FOR_CONDA)

    set_target_properties(${target} PROPERTIES PREFIX "" CXX_STANDARD 17)

    if(NETGEN_USE_GUI AND WIN32)
      target_link_libraries(${target} PUBLIC ngsolve)
    else(NETGEN_USE_GUI AND WIN32)
      target_link_libraries(${target} PUBLIC solve)
    endif(NETGEN_USE_GUI AND WIN32)

    if(WIN32)
      set_target_properties( ${target} PROPERTIES SUFFIX ".pyd" )
    else(WIN32)
      set_target_properties(${target} PROPERTIES SUFFIX ".so")
    endif(WIN32)

    set_target_properties(${target} PROPERTIES INSTALL_RPATH "${NGSOLVE_LIBRARY_DIR}")
endfunction()
endif(NGSOLVE_USE_PYTHON)
